from PIL import Image
from pystray import Icon, Menu, MenuItem

tray_queue = None


def on_item_click_open(icon_tray, item):
    print("on_item_click_open")
    tray_queue.put("open")


def on_item_click_exit(icon_tray, item):
    print("on_item_click_exit")
    icon_tray.stop()
    tray_queue.put("exit")


def start_tray(queue):
    global tray_queue
    tray_queue = queue
    start_icon_tray()


def start_icon_tray():
    open_item = MenuItem('打开', on_item_click_open)
    exit_item = MenuItem('退出', on_item_click_exit)
    menu = Menu(open_item, exit_item)
    image = Image.open('assets/logo.ico')
    icon_tray = Icon('Pystray', image, menu=menu)
    icon_tray.run()
